#pragma once

#include "myRBTree.h"

namespace gp
{
	template <class K, class V>
	class map
	{
		struct MapofKey
		{
			const K& operator()(const pair<K, V>& data)
			{
				return data.first;
			}
		};

	public:
		typedef typename RBTree<K, pair<const K, V>, MapofKey>::iterator iterator;
		typedef typename RBTree<K, pair<const K, V>, MapofKey>::const_iterator const_iterator;

		pair<iterator,bool> insert(const pair<K,V>& data)
		{
			return _t.Insert(data);
		}

		V& operator[](const K& key)
		{
			pair<iterator, bool> ret=_t.Insert(make_pair(key, V()));
			return ret.first->second;
		}

		iterator begin()
		{
			return _t.begin();
		}

		iterator end()
		{
			return _t.end();
		}

		const_iterator begin()const
		{
			return _t.begin();
		}

		const_iterator end()const
		{
			return _t.end();
		}

	private:
		RBTree<K, pair<const K, V>, MapofKey> _t;
	};
};
